package com.sgcc.fj.pmos.e_fj_mall.dialog;

import android.content.Context;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.lxj.xpopup.impl.PartShadowPopupView;
import com.lxj.xpopup.util.XPopupUtils;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.fj.pmos.e_fj_mall.adapter.GoodSortAdapter;
import com.sgcc.fj.pmos.e_fj_mall.bean.GoodSortBean;
import java.util.ArrayList;
import java.util.List;

/**
 * 新增户号-----地方电网弹窗
 */
public class GoodsSortPop extends PartShadowPopupView {
    GoodSortAdapter adapter;
    Context context;
    RecyclerView recyclerView;
    List<GoodSortBean> list = new ArrayList<>();
    LinearLayout llcontent;
    String[] selectList = {"默认随机排序", "销售电量升序", "销售电量降序", "预估价格升序", "预估价格降序", "上架时间升序", "上架时间降序"};

    public GoodsSortPop(@NonNull Context context, OnClickListener onClickListener) {
        super(context);
        this.context = context;
        this.onClickListener = onClickListener;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.pop_goods_sort;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        recyclerView = findViewById(R.id.recyclerView);
        LinearLayoutManager layoutManagerChart = new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManagerChart);
        llcontent = findViewById(R.id.ll_content);
        adapter = new GoodSortAdapter(context);

        adapter.setItemClickListener(new GoodSortAdapter.OnItemClickListener() {
            @Override
            public void OnItemsClickListener(int position, String text,int lastPostion) {
                if (onClickListener != null) {
                    onClickListener.onClick(position, text);
                }
                list.get(lastPostion).setSelect(false);
                list.get(position).setSelect(true);
                adapter.notifyDataSetChanged();
                dismiss();
            }
        });
        for (int i=0;i<selectList.length;i++){
            GoodSortBean bean=new GoodSortBean();
            bean.setName(selectList[i]);
            list.add(bean);
        }
        if(list.size()!=0){
            list.get(0).setSelect(true);
        }
        adapter.setNewData(list);
        adapter.notifyDataSetChanged();
        recyclerView.setAdapter(adapter);
    }

    //完全可见执行
    @Override
    protected void onShow() {
        super.onShow();
    }

    //完全消失执行
    @Override
    protected void onDismiss() {
    }

//    @Override
//    protected int getMaxHeight() {
//        return (int) (XPopupUtils.getScreenHeight(getContext()));
//    }

    @Override
    protected int getMaxWidth() {
        return (int) (XPopupUtils.getScreenWidth(getContext()));
    }

    @Override
    protected boolean onBackPressed() {
        return true;
    }


    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    /**
     * 设置确定取消按钮的回调
     */
    public OnClickListener onClickListener;


    public interface OnClickListener {
        /**
         * 点击确定按钮事件
         */
        public void onClick(int position, String text);

    }
}
